
var app = new Vue({
    el: '#app',
    data: {
        //内容
        cityFrom:{
            id: 0,
            city: "",
            province: "",
            longitude: "",
            latitude: ""
        },
        id: 0,
    },
    created() {
        if (sessionStorage.getItem("Cityid") != null) {
            this.id=sessionStorage["Cityid"];
            this.cityFrom.id=this.id;
            console.log(this.id)
            this.getCityLevel();
        }else{
            this.addCityLevel();
        }
    },
    methods:{
        addCityLevel(){
            this.$http.get('/admin/CityToAdd',{}).then(res => {
                $("div[id*='left_y']").hide();
                $("#" + res.body.left).show();
                $("#" + res.body.show_left).attr("style", "background: #293038;");
                $("#"+res.body.top).attr("style","background: #008fbf;");
                $(".top_admin .list-group").hide();
            });
        },
        getCityLevel(){
            const params = {
                id: this.id,
            };
            this.$http.post('/admin/CityOne',params,{emulateJSON:true}).then(res => {
                console.log(res);
                this.cityFrom.city=res.body.City.city;
                this.cityFrom.province=res.body.City.province;
                this.cityFrom.longitude=res.body.City.longitude;
                this.cityFrom.latitude=res.body.City.latitude;
                $("div[id*='left_y']").hide();
                $("#" + res.body.left).show();
                $("#" + res.body.show_left).attr("style", "background: #293038;");
                $("#"+res.body.top).attr("style","background: #008fbf;");
                $(".top_admin .list-group").hide();
            });
        },
        submitForm(){
            if (this.cityFrom.city===""||this.cityFrom.province===""||this.cityFrom.longitude===""||this.cityFrom.latitude===""){
                layer.msg('请将信息完整输入!', {
                    time: 2000
                });
                return false;
            }
            this.$http.post('/admin/CityAddOrUpdate',this.cityFrom,{emulateJSON:true}).then(res => {
                layer.msg('添加/修改 成功!', {
                    time: 2000
                });
                setTimeout(() => {
                    location.href = "/admin/city.html";
                }, 1000);
            });
        },
    }
})

window.onbeforeunload = function() {
    sessionStorage.removeItem("Cityid");
}